package com.sht.zdaicode.monitor;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class MonitorContextHolder {

    private static final ThreadLocal<MonitorContext> CONTEXT_HOLDER = new ThreadLocal<>();

    /**
     * 设置监控上下文
     */
    public static void setContext(MonitorContext context) {
        CONTEXT_HOLDER.set(context);
        log.debug("设置监控上下文: {}", context);
    }

    /**
     * 获取当前监控上下文
     */
    public static MonitorContext getContext() {
        return CONTEXT_HOLDER.get();
    }

    /**
     * 清除监控上下文
     */
    public static void clearContext() {
        MonitorContext context = CONTEXT_HOLDER.get();
        if (context != null) {
            log.debug("清除监控上下文: {}", context);
            CONTEXT_HOLDER.remove();
        }
    }
}
